﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SystemDoc_codemanage_tree.aspx.cs" Inherits="Ccit.OA.SystemDoc.SystemDoc_codemanage_tree" %>
<%@ Register assembly="Microsoft.Web.UI.WebControls, Version=1.0.2.226, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="Microsoft.Web.UI.WebControls" tagprefix="iewc" %>
<%@ Register TagPrefix="ccit" Namespace="Ccit.ServerControls" Assembly="Ccit.ServerControls.ActionForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>编号管理树形页面</title>
     <script language="javascript" type="text/javascript" src="../script/jquery.js"></script>
        <script language="javascript" type="text/javascript" src="../script/StringClass_Ext.js"></script>
        <script language="javascript" type="text/javascript" src="../script/jsonlib.js"></script>
        <script language="javascript" src="../script/jwindow.js" type="text/javascript"></script>
        <script language="javascript" src="../script/jcontrol.js" type="text/javascript"></script>
        <script language="javascript" src="../script/jbase64.js" type="text/javascript"></script>
</head>
<body>
    <ccit:ActionForm id="form1" runat="server">
   <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server"></asp:ScriptManager>    
    <input type="hidden" id="_hidClassType" runat="server" />
    <input type="hidden" id="_hidOriUpAddrId" runat="server" />
    <input type="hidden" id="_hidUpAddrId" runat="server" />  
    <input type="hidden" id="_hidAddNewSign" runat="server" /> <!-- 新增记录标志 -->
    <input type="hidden" id="_hidDelDepAddressId" runat="server" />  
    
        <!--保存后传来的主键id-->
    <input type="hidden" id="_hidNewColumnId" runat="server" />
    <input type="hidden" id="_hidExpandSign" runat="server" />
    <input type="hidden" id="_hidLevelStruct" runat="server" /> 
   
    <iewc:TreeView ID="trvDepAddress" runat="server">
    </iewc:TreeView>
    
    
    <script type="text/javascript">
    <!--
        var menuskin = "skin";
		var node = null;
		var menuname = "root";	 
		 
		function hideMenu() 
		{		    
			var obj = document.getElementById(menuname);
			if (null != obj && typeof(obj) != "undefined")
				document.getElementById(menuname).style.visibility = "hidden";
		}
		
		function highlighItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "highlight";
				event.srcElement.style.color = "white";
			}
		}
		function lowlightItem() 
		{
			if (event.srcElement.className == "menuitems") 
			{
				event.srcElement.style.backgroundColor = "";
				event.srcElement.style.color = "black";
				window.status = "";
			}
		}
		 
		///节点展开
		function trvDepAddress.onexpand()
		{	
		    /* Step 1：find current click TreeNode */	    
		    var nodeIndex = event.treeNodeIndex;	
		    //alert(nodeIndex);		
			if (typeof(nodeIndex) == "undefined"){			
				node = null;
				return false;
			}
			
			trvDepAddress.selectedNodeIndex = nodeIndex;
			node = trvDepAddress.getTreeNode(nodeIndex);
						
			/* Step 2: get asset type id，and get all child types */			
			var vNodeId = node.getAttribute("ID");
			var vNodeIdArray = vNodeId.split("_")
			var vAddressId = vNodeIdArray[0];
			var vLoadSign = vNodeIdArray[1];		
			
			if(vAddressId != "0" && vLoadSign == "0") {
			    var oSubNodes = node.getChildren();
			    var oSubNode;
			    for(var i = oSubNodes.length - 1; i >= 0; i --) {
			        oSubNode = oSubNodes[i];
			        oSubNode.remove();
			    }
			     var expandSign = $get("_hidExpandSign").value;//是否逐级展开 1：是
			    var levelStruct = $get("_hidLevelStruct").value;			    
			    PageMethods.GetSubAddrsByUpAddrId(vAddressId,nodeIndex,expandSign,levelStruct,ClientBack);
			    
			}
			hideMenu();
		}
		///节点收缩
		function trvDepAddress.oncollapse()
		{
			hideMenu();
		}
		 
		function ClientBack(vResult)
		{
		     var vNodeIdArray = vResult.split("_") 
		     var vOperType=vNodeIdArray[0];
		     switch(vOperType) {		       
                case "GetSubTypesByColumnId"://获取子节点
                     var vExeResult = vNodeIdArray[1];
	                 var nodeIndex = vNodeIdArray[2];
	                 var expandSign = vNodeIdArray[3];
	                 var levelStruct = vNodeIdArray[4];
	                 var parentNodeId = vNodeIdArray[5];
    			 
                    eval("var objResult="+vExeResult); 
                    for(var i=0;i<objResult.length;i++)
                    {
                       var oResult=objResult[i];
                       createSubTNodes(nodeIndex,oResult);//展开老祖宗
                    }         
                
                if(expandSign == "1") {//是逐级展开
                    var parentIdArr = levelStruct.split(",");
                    var iLen = parentIdArr.length;
                    var bGet = false;
                    for(var i = 0; i < iLen; i ++) {                                    
                        var colId = parentIdArr[i];     
                        if(!bGet) {
                            if(colId == parentNodeId) {
                                if(i == (iLen - 1)) {//如果到最底层，则逐级展开标志0
                                    $get("_hidExpandSign").value = "0";                                
                                }
                                bGet = true;
                                continue;
                            }
                        }
                        else {//true，展开下级                             
                            var ctrlNode = findTreeNode(colId);
                            var nodeAttrId = ctrlNode.getAttribute("ID");    
                            var vNodeIdArray = nodeAttrId.split("_")
	                        if(vNodeIdArray[1] == "1") {
	                            if(i == (iLen - 1)) {
                                    ctrlNode.setAttribute("EXPANDED",true);                               
                                }
                                else
	                                continue;
	                        }
	                        else {
	                            ctrlNode.setAttribute("EXPANDED",true);
	                            break;
	                        }
                        }
                    } 
                 }
                   break; 
                }
       		}
		 
        //追加子节点
        function createSubTNodes(nodeIndex,oResult) { 
			     var node = $get("trvDepAddress").getTreeNode(nodeIndex); 
			     var sClassType = $get("_hidClassType").value;
			     var vPageParam = "CodeID=" + oResult.CodeId+"&classType="+sClassType+"";
                 var encodeParam = base64encode(vPageParam);
                 vNavigateUrl = "SystemDoc_codemanage_view.aspx?" + encodeParam;
                 oSubNode = $get("trvDepAddress").createTreeNode();
		         oSubNode.setAttribute("ID",oResult.CodeId + "_" +"0");
		         oSubNode.setAttribute("Text",oResult.CodeName);
		         oSubNode.setAttribute("Type","root");
		         oSubNode.setAttribute("Target","iFrmEdit");
		         oSubNode.setAttribute("ImageUrl","../images/toolbar/filelogo.gif");
		         oSubNode.setAttribute("NavigateUrl",vNavigateUrl); 
		          
		         node.add(oSubNode);
		        /* set node load sign = 1 */
		        var vNodeId = node.getAttribute("ID");
		        var vNodeIdArray = vNodeId.split("_")
			    oResult.CodeId = vNodeIdArray[0]; 
			    node.setAttribute("ID",oResult.CodeId  + "_"+"1");		    
        } 
    //-->
    </script>
    
  </ccit:ActionForm>
</body>
</html>
